import axios from 'axios'
axios.defaults.withCredentials = true
const request = axios.create({
  baseURL: 'http://210.38.139.237/fudaoyuan/',
  timeout: 60000,
})
request.interceptors.request.use((config) => {
  return config
})
request.interceptors.response.use(
  (response) => {
    return response.data
  },
  (error) => {
    if (error.response.status === 401) {
      localStorage.removeItem('JSESSIONID')
      const casUrl =
        'https://authserver.gdou.edu.cn/authserver/login?service=http://210.38.139.237/fudaoyuan/auth/sso'
      window.location.href = casUrl
    }
    return Promise.reject(error)
  },
)
export default request
